#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
创建广电用户宽表示例CSV文件
"""
import csv
import random
import datetime
import os

def generate_sample_csv(file_path, row_count=1000):
    """生成示例CSV文件"""
    # 确保目录存在
    os.makedirs(os.path.dirname(file_path), exist_ok=True)
    
    # 定义字段名
    fieldnames = [
        'terminal_no', 'phone_no', 'sm_name', 'run_name', 'sm_code', 
        'owner_name', 'owner_code', 'run_time', 'addressoj', 'estate_name', 
        'open_time', 'force',
        # 标签字段
        'tv_consume_level', 'broadband_consume_level', 'is_retention', 
        'business_brand', 'tv_entry_level', 'broadband_entry_level', 'user_value_level'
    ]
    
    # 生成示例数据
    brands = ['品牌A', '品牌B', '品牌C', '品牌D']
    states = ['活跃', '暂停', '注销', '欠费']
    tv_consume_levels = ['低', '中', '高', '非常高']
    broadband_consume_levels = ['低', '中', '高']
    is_retention = ['是', '否']
    business_brands = ['高清套餐', '宽带套餐', '融合套餐', '基础套餐']
    entry_levels = ['新用户', '老用户', '忠诚用户']
    user_value_levels = ['低价值', '中价值', '高价值']
    
    with open(file_path, 'w', newline='', encoding='utf-8') as csvfile:
        writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
        writer.writeheader()
        
        for i in range(row_count):
            # 生成示例数据
            user_id = i + 10000
            now = datetime.datetime.now()
            open_date = now - datetime.timedelta(days=random.randint(30, 1000))
            
            row = {
                'terminal_no': f'T{i:08d}',
                'phone_no': f'138{i:06d}',
                'sm_name': random.choice(brands),
                'run_name': random.choice(states),
                'sm_code': f'BR{i%4+1:02d}',
                'owner_name': f'客户{i%10+1}级',
                'owner_code': f'OC{i%5+1:02d}',
                'run_time': now.strftime('%Y-%m-%d %H:%M:%S'),
                'addressoj': f'测试省测试市测试区{i%100+1}号',
                'estate_name': f'测试小区{i%50+1}期',
                'open_time': open_date.strftime('%Y-%m-%d %H:%M:%S'),
                'force': random.choice(['是', '否']),
                # 标签数据
                'tv_consume_level': random.choice(tv_consume_levels),
                'broadband_consume_level': random.choice(broadband_consume_levels),
                'is_retention': random.choice(is_retention),
                'business_brand': random.choice(business_brands),
                'tv_entry_level': random.choice(entry_levels),
                'broadband_entry_level': random.choice(entry_levels),
                'user_value_level': random.choice(user_value_levels)
            }
            
            writer.writerow(row)
    
    print(f"已生成示例CSV文件: {file_path}，包含{row_count}条数据")

if __name__ == "__main__":
    csv_file = "c:\\Users\\Administrator\\RuoYi-Vue01\\python_project\\media_users_wide_table.csv"
    generate_sample_csv(csv_file, 1000)